package pers.lws.erp.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @Classname ResultBody
 * @Description TODO
 * @Date 2020/2/21 15:23
 * @Created by x1c
 */
@Data
@AllArgsConstructor
public class ResultBody {
	/**
	 * 响应代码
	 */
	private Integer code;

	/**
	 * 响应消息
	 */
	private String msg;

	/**
	 * 响应结果
	 */
	private Object data;

    /**
     * 成功
     * @param msg
     * @param data
     */
    public ResultBody(String msg, Object data) {
        this.code = 200;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 失败
     * @param msg
     */
    public ResultBody(String msg) {
        this.code = -1;
        this.msg = msg;
    }

    /**
     * 成功
     * @param msg
     * @return
     */
    public static ResultBody success(String msg, Object data) {
        return new ResultBody(msg, data);
    }

    /**
     * 失败
     * @param msg
     * @return
     */
    public static ResultBody error(String msg) {
        return new ResultBody(msg);
    }

    /**
     * 自定义返回状态
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static ResultBody customStatus(Integer code, String msg, Object data) {
        return new ResultBody(code, msg, data);
    }

}
